package com.main.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.mobile.device.Device;


public class CommonUtils {
	private static String pattern = "yyyy-MM-dd";
	public static String formatDate(Date date){
	    SimpleDateFormat format = new SimpleDateFormat(pattern);
	    return format.format(date);
	}
	
	public static String getMD5(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] messageDigest = md.digest(input.getBytes());
            BigInteger number = new BigInteger(1, messageDigest);
            String hashtext = number.toString(16);
            // Now we need to zero pad it if you actually want the full 32 chars.
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            return hashtext;
        }
        catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
	
	public static String getRootPathByDevice(Device device){
		
//		if(device.isNormal()){
//			return "";
//		}
//		
//		if(device.isTablet()){
//			return Constant.TABLET;
//		}
//		
//		if(device.isMobile()){
			return Constant.MOBILE;
//		}
//		
//		return "";
	}

}
